<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/header.css">
		<style type="text/css">
			a {
				color: white;
			}
			
		</style>
	</head>


	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<a id="nicknameOk" class="mui-icon mui-icon-right-nav mui-pull-right" style="font-size: 16px;line-height: 25px;">完成</a>
			<h1 class="mui-title">设置昵称</h1>
		</header>

		<div class="mui-content">
			<div class="mui-input-row">
				<input type="text" id="nickname" style="height: 55px;line-height: 55px;" class="mui-input-speech mui-input-clear" placeholder="修改昵称"/>
			</div>
		</div>


	</body>
	<script src="../js/mui.js"></script>
	<script src="../js/app.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		mui.init({
				swipeBack: true //启用右滑关闭功能
			});
		
		mui.plusReady(function(){
			document.getElementById("nickname").value = app.getUserGlobalInfo().nickname;
			
			document.getElementById("nicknameOk").addEventListener("click",function(){
				mui.ajax(app.serverUrl+'/user/updateNickname',{
					//使用之前所存入的ip来进行通信
					data:{
						nickname: document.getElementById("nickname").value,
						id: app.getUserGlobalInfo().id
					},
					type:'post',//HTTP请求类型
					timeout:10000,//超时时间设置为10秒；
					success:function(data){ 
						if(data.status==200){
							var userInfo = data.data;//获取json对象中的用户对象
							app.setUserGlobalInfo(userInfo);
							var wobj = plus.webview.getWebviewById("wh-me.html");
							wobj.reload(true);
							app.showToast("昵称更新成功");
						}else{//服务器返回的数据为空,表明账户与密码验证失败
							app.showToast(data.data,"error");//弹出错误信息
						}
					},
					error:function(XMLHttpRequest, textStatus, errorThrown){
						if(textStatus=="timeout"){
							mui.toast("连接超时");//超过十秒报错
						}else if(textStatus=="error"){
							mui.toast("连接出错");
						}
					}
				});		
			})
			
			
			
		})
		
	</script>

</html>
